






































































































	
	
		printf("Wrong file format!\nYAM file system may be corrupted.\n");
		return;
	    printf("%0.2x", data[k]);
	   if (n < 0) {
	   n = read(fd, &buffer, SIZEOFSECTOR);
	   n = write(fd, &buffer, SIZEOFSECTOR);
	   printf("Error opening file!\n");
	   printf("Invalid number of bytes\n");
	   printf("Invalid sector number\n");
	   readSector(k, &buffer);
	   return;
	   return;
	   return;
	   writeSector(k, &buffer);
	   }
	close(fd);
	close(fd);
	fd = open(Unixfile, O_RDONLY);
	fd = open(Unixfile, O_WRONLY |O_CREAT | O_TRUNC, 0777);
	for (k=0; k < byteCount; k++)
	for (k=10; k < SIZEOFDISK; k++) {
	for (k=10; k < SIZEOFDISK; k++) {
	if (byteCount < 1  ||  byteCount > SIZEOFSECTOR) {
	if (fd < 0) {
	if (secNumber < 0  ||  secNumber >= SIZEOFDISK) {
	int k, fd, n;
	int k, fd, n;
	int k;
	n = read(fd, &root, sizeof(root));
	n = read(fd, InodeBitmap, sizeof(InodeBitmap));
	n = read(fd, SectorBitmap, sizeof(SectorBitmap));
	n = read(fd, node, sizeof(node));
	n = write(fd, &root, sizeof(root));
	n = write(fd, InodeBitmap, sizeof(InodeBitmap));
	n = write(fd, SectorBitmap, sizeof(SectorBitmap));
	n = write(fd, node, sizeof(node));
	printf("Sector %d:\n\n", secNumber);
	printf("\n\n");
	readSector(secNumber, (struct Sector*)data);
	struct Sector buffer;
	struct Sector buffer;
	unsigned char data[SIZEOFSECTOR];
	}
	}
	}
	}
	}
  
   
   
   
   
   
   
   
   
   
   
   
   
   
    
    
    
    
    
    
     
      
        
        
        
        
        
        
        
        
        
                
                    printf("%d ",node[root.entry[i].index].sect[j]);
                    printf("%hu ",indSector[k]);
                    size++;
                   freeMem(indSector[k]);
                   i = root.entry[k].index;
                   i = root.entry[k].index;
                   root.entry[k].index = 0;
                arg1[strlen(arg1)-1] = '\0';
                arg1[strlen(arg1)-1] = '\0';
                arg1[strlen(arg1)-1] = '\0';
                arg1[strlen(arg1)-1] = '\0';
                arg2[strlen(arg2)-1] = '\0';
                arg2[strlen(arg2)-1] = '\0';
                cat(arg1);
                close(fd);
                close(fd);
                close(fd);
                copy(arg1, arg2);
                display(var1,var2);
                export(arg1);
                for (k=0; k < filesize-4; k++)
                for(k=0;k<size;k++){
                freeMem(iSec);
                freeMem(node[i].indirect);
                freeMem(s);
                freeMem(s);
                freeMem(s);
                if (strcmp(root.entry[k].filename, YAMfile) == 0)
                if (strcmp(root.entry[k].filename, YAMfile) == 0) {
                if(node[root.entry[i].index].sect[j] != 0)
                if(temp != 0)
                import(arg1);
                link(arg1,arg2);
                printf("%d bytes copied.\n", node[i].size);
                printf("%d bytes copied.\n", node[i].size);
                printf("%d bytes copied.\n", node[i].size);
                printf("usage: cat <YAMfile>\n");
                printf("usage: copy <UNIXfile> <YAMfile>\n");
                printf("usage: display <numberofbytes> <sectornumber>\n");
                printf("usage: ln <sourcefile> <targetfile>\n");
                printf("usage: ls <directory name>\n");
                printf("usage: rm <YAMfile>\n");
                printf("usage: rm <YAMfile>\n");
                printf("usage: rm <YAMfile>\n");
                readSector(idr, (struct Sector*)indSector);
                readSector(node[i].indirect, (struct Sector*)indSector);
                return;
                return;
                return;
                rm(arg1);
                var1 = atoi(arg1);
                var2 = atoi(arg2);
                writeSector(iSec, (struct Sector *)indSector);
                }
                }
               ls(arg1);
               temp[p] = '\0';
            arg1 = strtok(NULL," ");
            arg1 = strtok(NULL," ");
            arg1 = strtok(NULL," ");
            arg1 = strtok(NULL," ");
            arg1 = strtok(NULL," ");
            arg1 = strtok(NULL," ");
            arg1 = strtok(NULL," ");
            arg1 = strtok(NULL," ");
            arg2 = strtok(NULL," ");
            arg2 = strtok(NULL," ");
            arg2 = strtok(NULL," ");
            else{
            else{
            else{
            else{
            else{
            else{
            else{
            else{
            filesize++;
            for(j = 0;j<4;j++){
            format();
            help();
            if(!arg1 | !arg2)
            if(!arg1 | !arg2)
            if(!arg1 | !arg2){
            if(!arg1 | (strcmp(arg1,"")==0))
            if(!arg1)
            if(!arg1)
            if(!arg1)
            if(!arg1)
            if((i+1) == k) 
            if((idr = node[root.entry[i].index].indirect) != 0){
            j = i;
            node[n].indirect = 0;
            printf("%s",temp);
            printf("%s",temp);
            printf("%s\t%d\t\t",root.entry[i].filename, node[root.entry[i].index].size);
            printf("\n");
            printf("invalid command, type 'help' to see options\n");
            readSector(indSector[i-4], (struct Sector *)temp);
            readSector(node[inode].sect[i], (struct Sector *)temp);
            return "That filename already exists";
            return EXIT_SUCCESS;
            size = (size - (4*512));
            size = node[root.entry[i].index].size;
            size = size/512;
            synch();
            temp = size%512;
            }
            }
            }
            }
            }
            }
            }
            }
            }
            }
            }
           InodeBitmap[n] = (InodeBitmap[n] | check);
           InodeBitmap[n] = 0;
           SectorBitmap[n] = (SectorBitmap[n] | check);
           SectorBitmap[n] = 0;
           close(fd);
           close(fd);
           count = 4;
           count = filesize;
           fbytes = read(fd, buffer, SIZEOFSECTOR);
           fbytes = read(fd, buffer, SIZEOFSECTOR);
           freeMem(node[i].sect[k]);
           freeMem(s);
           freeNode(i);
           if (fbytes <= 0  ||  s < 0) {
           if (fbytes <= 0  ||  s < 0) {
           if (root.entry[k].index > 0) {
           if (root.entry[k].index > 0) {
           indSector[k] = s;
           node[i].linkCount--;
           node[i].sect[k] = s;
           node[i].size += fbytes;
           node[i].size += fbytes;
           printf("%s\n", message);
           printf("%s\n", message);
           printf("Could not find %s\n", YAMfile);
           printf("Could not find %s\n", YAMfile);
           printf("Disk is full!\nFile was not copied.\n");
           printf("Error reading file %s\n", file);
           return (n*32)+pos;
           return (n*32)+pos;
           return;
           return;
           return;
           return;
           return;
           return;
           return;
           root.entry[n].index = 0;
           s = getMem();
           s = getMem();
           writeSector(s, (struct Sector *)buffer);
           writeSector(s, (struct Sector *)buffer);
           x = writeSector(n+1, (struct Sector*)(&SectorBitmap[n*SECSIZEINT]));
           x = writeSector(n+5, (struct Sector*)(&node[n*(INODENUMBER/4)]));
           }
           }
           }
           }
          empty = x;
          if (strcmp(root.entry[x].filename, name)==0)
         continue;
         continue;
         continue;
         continue;
         continue;
         continue;
        /* displays command prompt, get user input */
        /* handles copy command */
        /* handles display command */
        /* handles everything else */
        /* handles export command */
        /* handles import command */
        /* handles link commmand */
        /* handles logout command */
        /* handles ls command */
        /* handles rm command */
        /* handles synch commmand */
        InodeBitmap[0] = 0x80000000;
        SectorBitmap[0] = 0xFFC00000;
        char buffer[SIZEOFSECTOR];
        char* message;
        char* message;
        check = check >> 1;
        check = check >> 1;
        close(fd);
        command = strtok(line," ");
        else
        else if(strcmp(command, "cat")==0){
        else if(strcmp(command, "display")==0){
        else if(strcmp(command, "export")==0){
        else if(strcmp(command, "help\n")==0){
        else if(strcmp(command, "import")==0){
        else if(strcmp(command, "ln")==0){
        else if(strcmp(command, "logout\n")==0){
        else if(strcmp(command, "ls")==0){
        else if(strcmp(command, "rm")==0){
        else if(strcmp(command, "synch\n")==0){
        else if(strcmp(command,"format\n")==0){
        else{
        fbytes = read(fd, buffer, SIZEOFSECTOR);
        fbytes = read(fd, buffer, SIZEOFSECTOR);
        fd = open(file, O_RDONLY);
        fgets(line,sizeof(line),stdin);
        filesize = node[i].size / SIZEOFSECTOR;
        for (k=0; k < MAXROOTSIZE; k++) {
        for (k=0; k < MAXROOTSIZE; k++) {
        for (k=0; k < count; k++)
        for (k=1; k < 124; k++) {
        for (k=1; k < 4; k++) {
        for (n=0; n < MAXROOTSIZE; n++)
        for (n=0; n <= 3; n++)
        for (n=0; n <= 3; n++)
        for (n=0;n<INODENUMBER;n++) {
        for (n=1; n < SECSIZEINT*4; n++)
        for (n=1; n < SECSIZEINT; n++)
        freeNode(i);
        i = getNode();
        iSec = getMem();
        if ((InodeBitmap[n] & check) == 0) {
        if ((SectorBitmap[n] & check) == 0) {
        if ((node[i].size % SIZEOFSECTOR) > 0)
        if (fbytes < 0) {
        if (fbytes <= 0  ||  s < 0) {
        if (filesize > 4)
        if (filesize > 4) {
        if (i == 0) {
        if (i == 0) {
        if (node[i].linkCount > 1) {
        if (s < 0) {
        if (strcmp(message, "") != 0) {
        if (strcmp(message, "") != 0) {
        if(i < 4){
        if(i > 3){
        if(root.entry[i].index != 0){
        if(strcmp(command, "cp")==0){
        if(strcmp(root.entry[i].filename, YAMfile)==0){
        indSector[0] = s;
        int k, filesize, count;
        int k;
        int n,x;
        int n;
        int s, i, fd, fbytes, k, iSec;
        k++;
        message = add(YAMfile, i);
        message = add(newname, i);
        node[0].linkCount = 1;
        node[0].sect[0] = 9;
        node[0].size = SIZEOFSECTOR;
        node[0].type = 0;
        node[i].indirect = iSec;
        node[i].linkCount = 1;
        node[i].linkCount++;
        node[i].sect[0] = s;
        node[i].size += fbytes;
        node[i].size = fbytes;
        node[i].type = 1;
        printf("%d bytes copied.\n", node[i].size);
        printf("%s",temp);
        printf(">>");
        printf("filename not found\n");
        readSector(node[inode].indirect, (struct Sector*)indSector); 
        readSector(node[inode].sect[0],(struct Sector*)temp);
        return;
        return;
        s = getMem();
        s = getMem();
        synch();
        temp[p] = '\0';
        unsigned short int i = 0;
        unsigned short int i = 0;
        unsigned short int indSector[SECSIZEINT*2];
        unsigned short int indSector[SECSIZEINT*2];
        writeSector(iSec, (struct Sector *)indSector);
        writeSector(s, (struct Sector *)buffer);
        writeSector(s, (struct Sector *)buffer);
        x = writeSector(0, (struct Sector*)InodeBitmap);
        x = writeSector(9, (struct Sector*)(&root));
        }
        }
        }
        }
        }
        }
        }
        }
        }
        }
        }
        }
        }
        }
        }
        }
        }
        }
        }
        }
        }
        }
        }
        }
        }
        }
        }
        }
        }
        }
        }
        }
        }
      else
      if (name[x] == ',')
      if (name[x] == '.')
      if (name[x] == '_')
      if (name[x]>='0'  &&  name[x]<='9')
      if (name[x]>='A'  &&  name[x]<='Z')
      if (name[x]>='a'  &&  name[x]<='z')
      if (root.entry[x].index > 0) {
      return "Invalid filename";
      return "The directory is full";
      return;
      return;
      }
     check = 0x80000000;
     check = 0x80000000;
     for (pos=0; pos < 32; pos++) {
     for (pos=0; pos < 32; pos++) {
     return "Filename is too long";
     return "Invalid inode";
     }
     }
    char *arg1;
    char *arg2;
    char *command;
    char line[50];
    char temp[512];
    for(i=0;i<MAXROOTSIZE;i++){
    for(i=0;i<MAXROOTSIZE;i++){
    for(i=0;i<k;i++){
    format();
    if(!j){
    if((size%512) != 0)
    if(k == 0){
    if(node[inode].indirect != 0)
    inode = root.entry[j].index;
    int i,j,k,idr;
    int i,j,k;
    int var1;
    int var2;
    k = size / 512;
    p = size%512;
    printf("-----------------------------------------------\n");
    printf("COMMAND		help\n\n");
    printf("DESCRIPTION	help\n\n");
    printf("EXAMPLE		>> help\n\n");
    printf("File\tSize(in bytes)\tSectors\n");
    printf("\n\n");
    printf("\tCurrent commands are\n\n");
    printf("\t\tYAM  specifications\n\n");
    printf("\t\tadd specific sector in hexadecimal format\n\n");
    printf("\t\timage into a Unix file\n\n");
    printf("\t\tprogram to the disk image\n\n");
    printf("\tcat    displays the contents of a file to standard output\n\n");
    printf("\tcp     copy a file from Unix to  YAM\n\n");
    printf("\tdisplay displays a specific  number of bytes from\n");
    printf("\texport    save the contents of the entire RAM disk\n");
    printf("\tformat	formats (initializes) the RAM disk according to the\n");
    printf("\thelp	displays this information\n\n");
    printf("\timport    restore the YAM disk image from a Unix file\n\n");
    printf("\tln     creates a hard link\n\n");
    printf("\tlogout	   exit the shell program\n\n");
    printf("\tls     displays the YAM directory\n\n");
    printf("\tmkdir    makes a directory\n\n");
    printf("\trm       removes a file from YAM \n\n");
    printf("\tsynch    writes all YAM file system data/tables cached in\n");
    printf("found file: %s at %d", root.entry[j].filename, root.entry[j].index);
    readSector(9,(struct Sector *)&root);
    readSector(9,(struct Sector *)&root);
    return EXIT_SUCCESS;
    size = node[inode].size;
    unsigned short int indSector[SECSIZEINT*2];
    unsigned short int indSector[SECSIZEINT*2];
    unsigned short int size,inode,p;
    unsigned short int size,temp;
    while(1){
    }
    }
    }
    }
    }
    }
   InodeBitmap[location] = InodeBitmap[location] & mask;
   SectorBitmap[location] = SectorBitmap[location] & mask;
   char filename[14];
   for (n=0; n < SECSIZEINT*4; n++) {
   for (n=0; n < SECSIZEINT; n++) {
   for (x=0; x < MAXROOTSIZE; x++) {
   for (x=0; x < length; x++) {
   if (empty < 0)
   if (index <= 0)
   if (length > 13)
   if (position<1 || position>SECSIZEINT)
   if (position<10 || position>SECSIZEINT*4)
   int empty = -1;
   int length;
   int location;
   int location;
   int n;
   int n;
   int pos;
   int pos;
   int x;
   length = strlen(name);
   location = position/32;
   location = position/32;
   mask = mask >> position;
   mask = mask >> position;
   mask = ~mask;
   mask = ~mask;
   position = position % 32;
   position = position % 32;
   printf("filename is: %s\n",name);
   return  -1;
   return  -1;
   return "";
   root.entry[empty].index = index;
   strcpy(root.entry[empty].filename, name);
   struct DirEntry entry[MAXROOTSIZE];
   unsigned int check;
   unsigned int check;
   unsigned int mask = 0x80000000;
   unsigned int mask = 0x80000000;
   unsigned short int index;
   unsigned short int indirect;
   unsigned short int linkCount;
   unsigned short int sect[4];
   unsigned short int size;
   unsigned short int type;
   }
   }
   }
   }
 * 
 * 
 * 
 * 
 * @authors: Nick Phillips and to some extend Conrad Stack (naphill2 and jcstack, respectively)
 * @param DirEntry is a directory entry
 * @param DirSector creates a directory sector
 * @param Inode is used for the inodes
 * @param InodeBitmap is the bitmap for the inodes
 * @param SectorBitmap is the bitmap for the sectors
 * @param buffer a buffer for the data coming in
 * @param buffer holds data to be transfer to unix file
 * @param bufffer holds data to come into YAM
 * @param data hold the data to be displayed
 * @param fbytes holds the number of bytes in the file
 * @param fd holds the file pointer
 * @param fd is the file pointer
 * @param fd pointer to a file
 * @param filesize is the size of the file to remove
 * @param i holds the link count
 * @param i is a counter for the loops
 * @param i is the node at which the file resides
 * @param i,j,k are loop counters
 * @param i,j,k are loop counters
 * @param iSec is the indirect sector location if needed
 * @param idr is the indirect sector if it has one
 * @param indSector holds the list of indirect sectors
 * @param indSector holds the list of indirect sectors
 * @param indSector holds the list of more sectors to free
 * @param indSector is the list of the indirect sectors
 * @param inode is the inode of the file
 * @param k counter for loops
 * @param k is a loop counter
 * @param k is a loop counter
 * @param k is a loop counter
 * @param k loop counter
 * @param k loop counter
 * @param message holds a message on the results for the user
 * @param message is the message to the user about the results
 * @param n counter for for-loop
 * @param n holds return from write
 * @param n is a counter for the loops
 * @param n read pointer
 * @param node is the inode table
 * @param p is the offset into the last sector in which the file resides
 * @param root is the root directory
 * @param s holds mem location
 * @param size is the size of the file
 * @param size is the size of the file
 * @param temp is the number of indirect sectors are used
 * @param temp, holds the last sector
 * @param x holds return from writeSector
 * YAM disk
 * YAM.c implement the YAM filesystem complete with everything
 * address any bugs: jcstack@ncsu.edu
 * cat method prints out a YAM file
 * copy method copys a file from unix to the YAM file system
 * display method will display a specified number of bytes
 * export method exports YAM to a Unix file
 * from a specified sector
 * help method, ahh yes the help method
 * import method imports a unix file that was hopefully exported at some
 * link method makes another hard link to an existing file
 * ls method prints out all the files in YAM
 * point through YAM.
 * rm method removes a file from the YAM filesystem
 * settings.
 * system prompt.  Allows for most basic filesystem functions.
 * that you see when you type the 'help' command at the YAM
 */
 */
 */
 */
 */
 */
 */
 */ 
 */ 
 */ 
 */ 
 */ 
 */ 
 */ 
 */ 
 */ 
 */ 
 *@param index The inode number
 *@param name The filename
 *@param position The bit to set
 *@param position The inode bit to set
 *@return Message string
 *@return Position of free inode.  -1 if no inodes are free.
 *@return Position of free sector.  -1 if no sectors are free.
 *Adds the new file to the directory if there is room and it's not a duplicate.
 *Finds the first free inode (i.e. 0 value) and sets it to one.
 *Finds the first free sector (i.e. 0 value) and sets it to one.
 *Sets the bit at position to 0.
 *Sets the inode bit at position to 0.
#define  INODENUMBER  128
#define  MAXROOTSIZE  32
#define  SECSIZEINT  128
#include "DiskOperations.c"
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
*
*
*
*
*
*
*
*
*
*
* format method formats the YAM disk drive to its initial
* synch method moves contents of local buffer onto the 
/*
/*
/*
/*
/*
/*
/*
/*
/*
/*
/*
/* 
/* function list */
/* global variables */
/**
/**
/**
/**
/**
char* add(char name[], int index) {
char* add(char name[], int index);
int getMem() {
int getMem();
int getNode() {
int getNode();
int main(){
opened?: out.txt
struct DirEntry{
struct DirSector root;
struct DirSector{
struct Inode node[INODENUMBER];
struct Inode{
unsigned int InodeBitmap[SECSIZEINT];
unsigned int SectorBitmap[SECSIZEINT*4];
void cat(char YAMfile[]);
void cat(char YAMfile[]){
void copy(char file[], char YAMfile[]) {
void copy(char file[],char YAMfile[]);
void display(int byteCount, int secNumber) {
void display(int numOfBytes, int sec);
void export(char Unixfile[]) {
void export(char Unixfile[]);
void format() {
void format();
void freeMem();
void freeMem(int position) {
void freeNode();
void freeNode(int position) {
void help();
void help(){
void import(char Unixfile[]) {
void import(char Unixfile[]);
void link(char newname[], char YAMfile[]) {
void link(char newname[], char YAMfile[]);
void ls(char dirname[]);
void ls(char dirname[]){
void rm(char YAMfile[]) {
void rm(char YAMfile[]);
void synch() {
void synch();
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
};
};
};
